<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:xhtml />
<script type="text/javascript">
    function reset() {
        $("#select option:selected").removeAttr("selected");
        $("[id$=Dropdown]").removeAttr("selected");
        $("[id$=Anchor]").removeClass("selected");
        $("[id$=Dt]").hide();
        $("[id$=Dd]").hide();
        $("#showAll").removeAttr("disabled");
        $("#searchTitle").empty();
    }
    function selectSnp() {
        reset();
        $("#searchText").attr("title", "Enter one RS number or SNP alias on each line. Aliases should be in the format -2454G/A or 3953C/T.");
        $("#searchTitle").append("Enter one RS number or SNP alias on each line. Aliases should be in the format -2454G/A or 3953C/T.");
        $("#snpDropdown").attr("selected", "selected");
        $("#snpAnchor").addClass("selected");
        $("#geneDt").show();
        $("#geneDd").show();
        $("#chromoDt").show();
        $("#chromoDd").show();
        $("#keggDt").show();
        $("#keggDd").show();
    }
    function selectGene() {
        reset();
        $("#searchText").attr("title", "Enter one gene name on each line.");
        $("#searchTitle").append("Enter one gene name on each line.");
        $("#geneDropdown").attr("selected", "selected");
        $("#geneAnchor").addClass("selected");
        $("#chromoDt").show();
        $("#chromoDd").show();
        $("#keggDt").show();
        $("#keggDd").show();
        $("#pubDt").show();
        $("#pubDd").show();
        $("#penPubDt").show();
        $("#penPubDd").show();
    }
    function selectKegg() {
        reset();
        $("#searchText").attr("title", "Enter one pathway name on each line.");
        $("#searchTitle").append("Enter one pathway name on each line.");
        $("#keggDropdown").attr("selected", "selected");
        $("#keggAnchor").addClass("selected");
        $("#snpDt").show();
        $("#snpDd").show();
        $("#geneDt").show();
        $("#geneDd").show();
    }
    function selectAll() {
        reset();
        $("#searchText").attr("title", "Enter the name of the item you want to search for. Enter one name on each line for multiple items.");
        $("#searchTitle").append("Enter the name of the item you want to search for. Enter one name on each line for multiple items.");
        $("#allDropdown").attr("selected", "selected");
        $("#allAnchor").addClass("selected");
        $("#showAll").attr("disabled", "disabled");
    }

    function select() {
        switch(parseInt($("#searchSelect").val()))
        {
            case 0:
                selectAll();
                break;
            case 1:
                selectSnp();
                break;
            case 2:
                selectGene();
                break;
            case 3:
                selectKegg();
                break;
        }
    }

    $(document).ready(function() {
        $("[id$=Advanced]").hide();
        $("#advancedSearch").hide();
        $("#advanceExpand").click(function() {
            $("#advancedSearch").toggle();
            if ($("#advancedSearch").is(":hidden"))
            {
                $("[id$=Dd] *").attr("disabled", "disabled");
            }
            else
            {
                $("[id$=Dd] [id!=selectedPubli]").removeAttr("disabled");
            }
            $("#advanceExpand span").toggle();
        });
        $("#searchSelect").change(function() {
            select();
        });

        <logic:notPresent name="user_name">
            $("#selectedPubli").attr("disabled", "disabled");
        </logic:notPresent>
        select();
    });
</script>
<div id="search" class="content input">
    <h2>Search</h2>
    <html:errors property="search" />
    <html:form action="searchSubmit">
        <div id="main">
            <p>Search&nbsp;
                <html:select styleId="searchSelect" property="searchSelect">
                    <html:option styleId="allDropdown" value="0">All</html:option>
                    <html:option styleId="snpDropdown" value="1">SNPs</html:option>
                    <html:option styleId="geneDropdown" value="2">Genes</html:option>
                    <html:option styleId="keggDropdown" value="3">KEGG Pathways</html:option>
                </html:select>
            </p>
            <span id="searchTitle" class="title">Enter one RS number or SNP alias on each line. Aliases should be in the format -2454G/A or 3953C/T.</span>
            <html:textarea property="searchText" styleId="searchText" rows="5" cols="20" style="width: 20em;" />
            <html:submit property="submitType" value="Search" />
            <html:submit property="submitType" styleId="showAll" value="Show All" /><br />
        </div>
        <p><a id="advanceExpand"><span>+</span><span class="minus">-</span> Advanced Search</a></p>
        <div id="advancedSearch">
            <p>Search will return all items that match any of the search criteria.</p>
            <p>
                <a id="allAnchor" onclick="selectAll();">All</a> |
                <a id="snpAnchor" onclick="selectSnp();">SNP</a> |
                <a id="geneAnchor" onclick="selectGene();">Gene</a> |
                <a id="keggAnchor" onclick="selectKegg();">Kegg Pathway</a>
            </p>
            <dl>
                <dt id="snpDt">SNP</dt>
                <dd id="snpDd">
                    <span class="title">Enter one RS Number or SNP alias on each line. Alias should be in the format -2454G/A or 3953C/T</span>
                    <html:textarea property="snps" title="Enter one RS Number or SNP alias on each line. Alias should be in the format -2454G/A or 3953C/T" rows="5" cols="20" />
                </dd>
                <dt id="geneDt">Gene</dt>
                <dd id="geneDd">
                    <span class="title">Enter one gene on each line.</span>
                    <html:textarea property="genes" title="Enter one gene on each line." rows="5" cols="20" />
                </dd>
                <dt id="chromoDt">Chromosome</dt>
                <dd id="chromoDd">
                    <span class="title">Enter one chromosome on each line.</span>
                    <html:textarea property="chromosomes" title="Enter one chromosome on each line." rows="5" cols="20" />
                </dd>
                <dt id="keggDt">Kegg Pathway</dt>
                <dd id="keggDd">
                    <span class="title">Enter one pathway on each line.</span>
                    <html:textarea property="pathways" title="Enter one pathway on each line." rows="5" cols="20" />
                </dd>
                <dt id="pubDt">Publication</dt>
                <dd id="pubDd">
                    <html:select property="selectedPubli">
                        <html:options property="availablePubliIds" labelProperty="availablePubliNames" />
                    </html:select>
                </dd>
                <dt id="penPubDt">Pending Publication</dt>
                <dd id="penPubDd">
                    <html:select styleId="selectedPubli" property="selectedPendPubli">
                        <logic:present name="user_name">
                            <html:options property="availablePendPubliIds" labelProperty="availablePendPubliNames" />
                        </logic:present>
                        <logic:notPresent name="user_name">
                            <html:option value="-1">Please login to use.</html:option>
                        </logic:notPresent>
                    </html:select>
                </dd>
            </dl>
            <p><html:submit property="submitType" value="Search" styleClass="bottomSubmit" /></p>
        </div>
    </html:form>
</div>